//
//  ViewController.m
//  Timer01
//
//  Created by 大宝 刘 on 11-11-17.
//  Copyright (c) 2011年 北京帷幄昊合数字娱乐科技有限公司. All rights reserved.
//

#import "ViewController.h"

@implementation ViewController
@synthesize timer = _timer;
@synthesize pageNo = _pageNo;

@synthesize helloLabel;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1 
                                                  target:self 
                                                selector:@selector(getResult)
                                                userInfo:nil repeats:YES];
    
    self.pageNo = 0;

    [self getResult];
}
                  


- (void)viewDidUnload
{
    [self setHelloLabel:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

#pragma mark - 自定义函数

- (void) getResult {
    NSString *curTime = [self getCurrentTime];
    
    if(_pageNo < 10) {
        _pageNo++;
    } else {
        _pageNo = 0;
    }
        
    NSString *result = [[NSString alloc]initWithFormat:@"hello %@ %d", curTime, self.pageNo];
    
    self.helloLabel.text =  result;
}

- (NSString *) getCurrentTime {
    NSDateFormatter *formater = [[NSDateFormatter alloc]init];
    
    NSDate *curDate = [NSDate date];//获取当前日期
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"]; // 设置中国时区
    [formater setTimeZone:timeZone];
    
    //    [formater setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; 
    [formater setDateFormat:@"HH:mm:ss"]; // 设置时间格式，仅显示当前时间
    NSString *curTime = [formater stringFromDate:curDate];
    
    return curTime;
}

@end
